<template>
  <BasicDrawer @register="registerDrawer" destroyOnClose :title="title" :width="drawerWith" :showFooter="true" @ok="handleOk">
    <GoodsWechatSet ref="goodsWechatSet"></GoodsWechatSet>
  </BasicDrawer>
</template>
<script lang="ts" name="GoodsWechatSetDrawer" setup>
import { getCurrentInstance, ref, unref } from 'vue';
import { BasicDrawer, useDrawerInner } from '@apps/antd-admin/src/components/drawer';
import GoodsWechatSet from '@apps/ant-bus/src/views/business/goods/goods/components/GoodsWechatSet.vue';
import { useAppInject } from '@apps/antd-admin/src/hooks/web/use-app-inject';
const { getIsMobile } = useAppInject();
const drawerWith = ref('40%');
if (unref(getIsMobile)) {
  drawerWith.value = '80%';
}
// 声明Emits
const emit = defineEmits(['register', 'success']);
const ctx: any = getCurrentInstance();
let title = ref('');
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async data => {
  let record = data.record;
  title.value = record.goodsName + '上架公众号';
  ctx.refs['goodsWechatSet'].setData(record);
});

/**
 * 确定按钮事件
 */
async function handleOk() {
  try {
    setDrawerProps({ confirmLoading: true });
    ctx.refs['goodsWechatSet'].handleSubmit(callback => {
      //执行子组件回调事件
      callback && callback(emit);
      //关闭抽屉
      closeDrawer();
      setDrawerProps({ confirmLoading: false });
    });
  } catch (err) {
    setDrawerProps({ confirmLoading: false });
  }
}
</script>
